// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";

export default defineConfig(() => {
  return {
    // 配置选项
    base: "/ui-demo",
    plugins: [commitInfo(), react()],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
        "@ct0/ui": path.resolve(__dirname, "../es"),
      },
    },
    build: {
      outDir: "dist/ui-demo",
    },
    server:{
      open: true,
      fs: {
        allow: ['..']
      }
    }
  };
});

function commitInfo() {
  return {
    name: "commit-info",
    transformIndexHtml(html) {
      return html.replace(
        "{COMMIT_INFO}",
        process.env.COMMIT_INFO?.replace('"', " ")
      );
    },
  };
}
